import time
from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://www.suning.com/")
driver.find_element_by_xpath("//*[@id='searchKeywords']").send_keys("五常大米")
driver.find_element_by_xpath("//*[@id='searchSubmit']").click()
time.sleep(3)
driver.find_element_by_xpath("//*[@id='0000000000-12364921898']/div/div/div[2]/div[2]/a").click()# 点击进入加入购物车页面
time.sleep(3)
# 获取新页面
handles = driver.window_handles
driver.switch_to.window(handles[-1])
time.sleep(2)
driver.find_element_by_xpath("//*[@id='addCart']").click()
time.sleep(3)
driver.find_element_by_xpath('/html/body/div[38]/div/div[2]/div/div[1]/a').click()
time.sleep(3)
driver.find_element_by_xpath('//*[@id="cart-wrapper"]/div[3]/div/div/div[2]/div[2]/a').click()
time.sleep(3)
driver.quit()
